package admin.board.genre.action;

import java.sql.SQLException;
import java.util.List;

import admin.board.board_list.dao.BoardlistDao;
import admin.board.board_list.dto.BoardlistDto;
import admin.board.genre.dao.GenreDao;
import admin.board.genre.dto.GenreDto;
import admin.common.AdminUtil;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class WriteAction extends ActionSupport {
	private GenreDao dao;
	private GenreDto dto;
	private BoardlistDao boardlistDao;
	private List<BoardlistDto> boardList;
	private List<Integer> possibleNumList;
	
	private int genre_no;
	private int board_no;
	private String genre_name;
	
	public WriteAction() {
		dao = GenreDao.getInstance();
	}

	public String form() throws SQLException {
		boardlistDao = BoardlistDao.getInstance();
		boardList = boardlistDao.list();
		possibleNumList = AdminUtil.checkPossibleNum(1, 10, 1, dao);
		
		return SUCCESS;
	}
	
	public String possibleNumCheck() throws SQLException {
		possibleNumList = AdminUtil.checkPossibleNum(
				board_no*10-9, board_no*10, board_no, dao);
		
		return SUCCESS;
	}
	
	public String execute() throws SQLException {
		dto = new GenreDto();
		dto.setAll(board_no, genre_no, genre_name);
		dao.insert(dto);
		
		return SUCCESS;
	}
	
	public List<BoardlistDto> getBoardList() {
		return boardList;
	}
	
	public List<Integer> getPossibleNumList() {
		return possibleNumList;
	}

	public int getGenre_no() {
		return genre_no;
	}

	public void setGenre_no(int genre_no) {
		this.genre_no = genre_no;
	}

	public int getBoard_no() {
		return board_no;
	}

	public void setBoard_no(int board_no) {
		this.board_no = board_no;
	}

	public String getGenre_name() {
		return genre_name;
	}

	public void setGenre_name(String genre_name) {
		this.genre_name = genre_name;
	}
}
